(function ($)
{
  $.fn.news = function (options)
    {
      var defaults = {
                       limit:    4,
                       username: 'wolfsoftwarevn'
                     };
      var options = $.extend(defaults, options);

      return this.each(function (options)
        {
          var act = $(this);
          var $tweetList;
          var tweetMonth = '';
          var shortMonths = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
          var api = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=";
          var count = "&include_rts=false&exclude_replies=true&count=";

          $.getJSON(api + defaults.username + count + defaults.limit + "&callback=?", act, function (data)
            {
              act.empty();

              $.each(data, function (i, item)
                {
                  $tweetList = $('<div class="news">').appendTo(act);

                  $tweetList.append('<p>' + item.text.replace(/#(.*?)(\s|$)/g, '<span class="hash">#$1 </span>').replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, '<a href="$&">$&</a> ').replace(/@(.*?)(\s|\(|\)|$)/g, '<a href="http://twitter.com/$1">@$1 </a>$2')+'</p>');
                  for (var iterate = 0; iterate <= 12; iterate++)
                    {
                      if (shortMonths[iterate] == item.created_at.substr(4, 3))
                        {
                          tweetMonth = iterate + 1;
                          if (tweetMonth < 10)
                            {
                              tweetMonth = '0' + tweetMonth;
                            }
                        } 
                    }	
                  $tweetList.append('<p class="date"> ' + item.created_at.substr(8, 2) + '/' + tweetMonth + '/' + item.created_at.substr(26,4) + ' ' + item.created_at.substr(11,8) + '</>');
                  $tweetList = $('</div>').appendTo(act);
                });
            });
        });
    }
})(jQuery);
